
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Asignar Personal</title>
        <link href="/css/style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" language="javascript" src="JQuery/js/jquery-1.3.min.js"></script>
        <script type="text/javascript" src="JQuery/js/jquery-1.3.2.min.js"></script>
        <script type="text/javascript">
            function asignopersonal(){
                var p = document.getElementsByName("personalseleccionado");
                var j=0;
                var array = new Array();
                for(var i=0;i < p.length;i++){
                    if(p[i].checked){
                        array[j] = p[i].value;
                        j++;
                    }              
                }  
                var valores = array.join(",");
                document.forms[2].action="/anadirpersonalalevento";
                document.forms[2].variable1.value=valores;
                document.forms[2].submit();
            }

            function marcar_todos(){
                var p = document.getElementsByName("personalseleccionado");      
                for(var i=0;i<(p.length);i++){       
                    if(p[i].checked==0){                        
                        p[i].checked=1;
                    }
                }
            }

            function desmarcar_todos(){
                var p = document.getElementsByName("personalseleccionado");
                for(var i=0;i<(p.length);i++){
                    if(p[i].checked==1){
                        p[i].checked=0;
                    }
                }
            }
        </script>

    </head>

    <body>
        <form action="/listadoeventos" >
            <input type="image" src="/stylesheets/fondo_pagina.png">
        </form>

        <center><h1>Plantilla del Evento</h1></center><br>

        <div id="cent2">
            <input type="button" name="boton" onclick="marcar_todos()" value="Marcar todos"/>
            <input type="button" name="boton2" onclick="desmarcar_todos()" value="Desmarcar todos"/>
        </div>
        <br>

        <c:choose>
            <c:when test="${!empty plantilla}">
                <c:forEach var="camarero" items="${plantilla}">
                    <fieldset>
                        <fieldset>
                            <center><legend>Información personal</legend></center>
                            <b>Nombre:</b>
                            <c:out value="${camarero.nombre}"/><br/>
                            <b>Capacidad:</b>
                            <c:out value="${camarero.categoria}"/><br/>
                            <b>Fecha ocupadas:</b>
                            <c:out value="${camarero.disponibilidad}"/><br/>

                        </fieldset>

                        <table>
                            <tr>
                                <td>

                                    <form action="" method="get" name="f1">
                                        <input type="checkbox" name="personalseleccionado" value="${camarero.idString}"> Asignar<br>
                                        <input type="hidden" name="id_evento" value="${evento.idString}" />
                                    </form>

                                    <form name="frmEnviar" action="si" method="get">
                                        <input type="hidden" name="variable1" value="">
                                        <input type="hidden" name="num" value="">
                                        <input type="hidden" name="id_evento" value="${evento.idString}" />
                                    </form>


                                </td>

                            </tr>
                        </table>


                    </fieldset>
                </c:forEach>

                <input id="asignar" type="submit" value="Asignar" onClick="asignopersonal();"/>

            </c:when>
            <c:otherwise>
                <center><b>No hay personal guardado.</b></center>
            </c:otherwise>
        </c:choose>



    </body>
</html>
